package com.example.win.android_banduyujia.peopleactivity.fragment.projectfragment.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.win.android_banduyujia.R;
import com.example.win.android_banduyujia.peopleactivity.fragment.projectfragment.adapter.FragmentAdapter;
import com.example.win.android_banduyujia.peopleactivity.ui.layout.RefreshLayout;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by huchun on 2015/8/21.
 */
public class DropFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener, RefreshLayout.OnLoadListener {

    private Context context;

    private RefreshLayout swipeLayout;
    private ArrayList<HashMap<String, String>> list;
    private View header;

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view=inflater.inflate(R.layout.fragment_wait_page, null);

        InitVertical(view);
        setListener();

        header =getLayoutInflater(savedInstanceState).inflate(R.layout.layout_refresh_header, null);
        return view;

    }

    private void setListener() {
        swipeLayout.setOnRefreshListener(this);
        swipeLayout.setOnLoadListener(this);
    }

    private void InitVertical(View view) {
        RecyclerView  recyclerView = (RecyclerView) view.findViewById(R.id.revyvler_view_vertical);
        LinearLayoutManager  layoutManager = new LinearLayoutManager(context);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);

        String[]  dataset = new String[2];
        for(int i=0; i<dataset.length; i++){
            dataset[i]="item"+i;
        }

        FragmentAdapter  adapter = new FragmentAdapter(dataset);
        recyclerView.setAdapter(adapter);

        swipeLayout= (RefreshLayout)view.findViewById(R.id.swipe_container);
        swipeLayout.setOnRefreshListener(this);
        swipeLayout.setColorScheme(android.R.color.holo_blue_bright,
                android.R.color.holo_green_light,
                android.R.color.holo_orange_light,
                android.R.color.holo_red_light);

        list = new ArrayList<HashMap<String,String>>();
        for(int i=0; i <10;i++){
            list.add(new HashMap<String, String>());
        }
    }

    @Override
    public void onRefresh() {
        swipeLayout.postDelayed(new Runnable() {
            @Override
            public void run() {

                swipeLayout.setRefreshing(false);
            }
        },1000);
    }

    @Override
    public void onLoad() {
        swipeLayout.postDelayed(new Runnable() {
            @Override
            public void run() {

                swipeLayout.setLoading(false);
            }
        },1000);
    }
}
